﻿@using LightSO.CMS.Model.EasyUI
@{
    Treegrid Treegrid = null;
    if (ViewBag.Treegrid == null)
    {
        Treegrid = LightSO.CMS.Model.EasyUI.Treegrid.Create(ViewBag);
    }
    else
    {
        Treegrid = ViewBag.Treegrid;
    }
    string version = "20150605";
}


<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Html.Partial("~/Views/Shared/Shared.cshtml")

    <script type="text/javascript">
    @RenderSection("EnumDefine", false)
    var columns_@(Treegrid.Id) = [
        @if(Treegrid.Columns.Count>0)
        {
        @:[
                var i = 0;
            foreach (var item in Treegrid.Columns)
            {
                Column col = item.Value;
                @:{
                            @:  field: '@(col.Id)', title: '@(col.Title)', width: @(col.Width), hidden: @((col.Id == "Id" ? "true" : (col.Hidden ? "true" : "false"))), sortable: @(col.Sortable ? "true" : "false"), align: '@(col.Align.ToString().ToLower())',nowrap: @(col.NoWrap ? "true" : "false"),
                        @:  formatter: function(value, row, index){                                                                                                                                                               
                                            string columnName = col.Id;
                        if (!string.IsNullOrWhiteSpace(columnName))
                        {
                            var script = RenderSection(string.Format("{0}ColumnFormat", columnName), false);
                            if(script != null)
                            {
                                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"</?script[^<>]*>");
                                @Html.Raw(regex.Replace(script.ToHtmlString(), string.Empty));
                                @:value = this.formatter(value, row, index);
                                                }
                        }
                        @:return typeof(value) != "string" && value == 0 ? "" : value;
                                       @:}
                            @:}
                    i++;
                if (i != Treegrid.Columns.Count)
                {
                    @:,
                    }
            }
        @:]
            }
    ];

        var rowStyler_@Treegrid.Id = function (index, row) {
                @{
                    var rowStyler = RenderSection("RowStyler", false);
                    if (rowStyler != null)
                    {
                        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"</?script[^<>]*>");
                        @Html.Raw(regex.Replace(rowStyler.ToHtmlString(), string.Empty));
                        @:return this.rowStyler(index, row);
                    }
                }
        };

        var onClickRowEvent_@Treegrid.Id = function (index, row) {
                @{
                    var onClickRowEvent = RenderSection("OnClickRow", false);
                    if (onClickRowEvent != null)
                    {
                        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"</?script[^<>]*>");
                        @Html.Raw(regex.Replace(onClickRowEvent.ToHtmlString(), string.Empty));
                        @:this.onClickRow(index, row);
                    }
                }
        };

        var onDblClickRowEvent_@Treegrid.Id = function (index, row) {
                @{
                    var onDblClickRowEvent = RenderSection("OnDblClickRow", false);
                    if (onDblClickRowEvent != null)
                    {
                        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"</?script[^<>]*>");
                        @Html.Raw(regex.Replace(onDblClickRowEvent.ToHtmlString(), string.Empty));
                        @:this.onDblClickRow(index, row);
                    }
                }
        };

    $(function () {
        easymvc.createTreegrid('@(Treegrid.Id)', '@(Html.Raw(Treegrid.Url))',easymvc.view);
    });
    </script>
    @if (!string.IsNullOrWhiteSpace(Treegrid.ScriptSrc))
    {
        <script type="text/javascript" src="@Treegrid.ScriptSrc?version=@version"></script>
    }
</head>
<body>


    <table id="@(Treegrid.Id)" data-options="singleSelect:@(Treegrid.SingleSelect ? "true" : "false")"></table>
    @RenderBody()

    @*右键菜单*@
    <div id="popupmenu_@(Treegrid.Id)" class="easyui-menu" style="width:120px;">
        @RenderSection("PopupMenu", required: false)
        <div class="menu-sep"></div>
        <div id="menuItemReload" onclick="easymvc.treegridReload('@(Treegrid.Id)');" data-options="iconCls:'icon-reload'">刷新</div>
    </div>

    @*工具条面板组*@
    <div id="treegrid_toolbar_@(Treegrid.Id)" style="display:none;">
        @*按钮组*@
        @{var buttons = RenderSection("ToolbarButtonsGroup", false);}
        @if (buttons != null)
        {
            <div class="treegrid-toolbar">
                @Html.Raw(buttons.ToHtmlString())
            </div>
        }
        @{var filter = RenderSection("ToolbarFilter", false);}
        @if (filter != null)
        {
            <div class="treegrid-toolbar">
                @Html.Raw(filter.ToHtmlString())
            </div>
        }
        @*工具条菜单*@
        <div class="treegrid-toolbar" style="border-bottom-width:0px;">
            @RenderSection("ToolbarMenu", false)
            <a id="btnTreegridReload" onclick="easymvc.treegridReload('@(Treegrid.Id)');" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
        </div>
    </div>


</body>
</html>
